package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Investuser;
import com.gxa.p2p.service.InvestuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/invest")

//@Transactional
@Api(value = "投资用户操作接口")

public class InvestuserController {
    @Autowired
    InvestuserService investuserService;
    /**
     * 周志远
     * @param
     * @return
     */
    @PostMapping("/findInvestorByPage")
    @ApiOperation("查询投资用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "投资用户姓名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "phone",value = "投资用户手机",required = false,dataType = "String"),
            @ApiImplicitParam(name = "isReal",value = "投资用户实名状态",required = false,dataType = "Boolean"),
            @ApiImplicitParam(name = "lockState",value = "投资用户状态",required = false,dataType = "Boolean"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "每页显示数",required = true,dataType = "Integer")

    })
    public Map findInvestorByPage (String name, String phone, Boolean isReal, Boolean lockState, String from, Integer page,Integer size){
        List<Map<String, Object>> investuserByPage = investuserService.findInvestuserByPage(name, phone, isReal, lockState, from, page, size);
        List<Map<String, Object>> count = investuserService.count(name, phone, isReal, lockState, from, null, null);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(investuserByPage);
        jsonResult.put("count",count.size());
        return jsonResult.getDataMap();
    }
    /**
     * 周志远
     * @param
     * @return
     */
    @PostMapping("/investorDetail")
    @ApiOperation("查看投资用户详细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "投资用户编号",required = true,dataType = "Long")


    })
    public Map investorDetail (Long id){
        Investuser investuser = investuserService.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(investuser);
        return jsonResult.getDataMap();

    }
    /**
     * 周志远
     * @param
     * @return
     */
    @PostMapping("/investorPwd")
    @ApiOperation("投资用户密码管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "投资用户编号",required = true,dataType = "Long"),
            @ApiImplicitParam(name = "loginPwd",value = "投资用户登录密码",required = true,dataType = "String"),
            @ApiImplicitParam(name = "dealPwd",value = "投资用户交易密码",required = true,dataType = "String")
    })
    public Map investorPwd (Long id,String loginPwd,String dealPwd){
        investuserService.updatePwd(id, loginPwd, dealPwd);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }
    /**
     * 周志远
     * @param
     * @return
     */
    @PostMapping("/updateInvestor")
    @ApiOperation("投资用户修改 (测试只传注释中修改开头的字段)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "修改用户的编号",required = true,dataType = "Long"),
            @ApiImplicitParam(name = "phone",value = "修改用户的电话",required = true,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "修改用户的姓名",required = true,dataType = "String"),
            @ApiImplicitParam(name = "cardNumber",value = "修改用户的身份证号码",required = true,dataType = "String"),
            @ApiImplicitParam(name = "bankName",value = "修改用户的银行名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "subName",value = "修改用户的支行名称",required = true,dataType = "String"),
            @ApiImplicitParam(name = "bankId",value = "修改用户的银行卡号",required = true,dataType = "String"),
            @ApiImplicitParam(name = "lockState",value = "修改用户的锁定状态",required = true,dataType = "Boolean"),
            @ApiImplicitParam(name = "remarks",value = "修改用户的备注",required = true,dataType = "String")

    })
    public Map updateInvestor (Investuser investuser){
        investuserService.updateInvestuser(investuser);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();

    }
}
